// Copyright (c) 2006 Zorm
// Released under the MIT License

#include "PCH.h"
#include "Common.h"

void RadarInformation::Draw() {
	glPushMatrix();
	glTranslated(m_centerx - m_panx - m_latitude * m_scale, m_centery - m_pany - m_longitude * m_scale, 0.0);
	glPushMatrix();
	glScaled(m_scale, m_scale, 0.0);
	//glColor4f(0.0f, 1.0f, 1.0f, 1.0f);
	//scale size
	for(VectorPointIter iter = radarData.begin(); iter != radarData.end(); iter++) {
		PointLatLonR *pt = (*iter);
		//ATH::Instance()->GetLog()->LogEvent(Log::LOG_INFO, TEXT("(%i, %i) (%i, %i) (%i, %i) (%i, %i)\n"), pt->lat[0], pt->lon[0], pt->lat[1], pt->lon[1], pt->lat[2], pt->lon[2], pt->lat[3], pt->lon[3]);
		SetColor(pt->level);
		glBegin(GL_QUADS);
		glVertex2f(pt->lat[0], pt->lon[0]);
		glVertex2f(pt->lat[1], pt->lon[1]);
		glVertex2f(pt->lat[2], pt->lon[2]);
		glVertex2f(pt->lat[3], pt->lon[3]);
		glEnd();
		glBegin(GL_LINES);
		glVertex2f(pt->lat[0], pt->lon[0]);
		glVertex2f(pt->lat[1], pt->lon[1]);

		glVertex2f(pt->lat[1], pt->lon[1]);
		glVertex2f(pt->lat[2], pt->lon[2]);

		glVertex2f(pt->lat[2], pt->lon[2]);
		glVertex2f(pt->lat[3], pt->lon[3]);

		glVertex2f(pt->lat[3], pt->lon[3]);
		glVertex2f(pt->lat[0], pt->lon[0]);
		glEnd();
	}
	glPopMatrix();
	glPushMatrix();
	glTranslated((m_latitude * m_scale) - m_latitude, (m_longitude *m_scale) - m_longitude, 0.0);
	//no scale size
	glColor4f(1.0f, 1.0f, 0.0f, 1.0f);
	glBegin(GL_QUADS);
		glVertex2i(m_latitude, m_longitude + 3);
		glVertex2i(m_latitude + 3, m_longitude);
		glVertex2i(m_latitude, m_longitude - 3);
		glVertex2i(m_latitude - 3, m_longitude);
	glEnd();
	ATH::Instance()->GetGLContext()->DrawString(m_latitude, m_longitude, "test");
	glPopMatrix();
	glPopMatrix();
}

void RadarInformation::IncreaseScale(short delta) {
	m_scale += delta * .25;// * .001;
}
void RadarInformation::DecreaseScale(short delta) {
	m_scale -= delta * .25;// * .001;
	if (0.001 > m_scale) {
		m_scale = 0.001;
	}
}

void RadarInformation::SetColor(unsigned char level) {
	switch (level) {
		case 0:
			glColor4ub(0, 0, 0, 255);
			return;
		case 1:
			glColor4ub(0, 236, 236, 255);
			return;
		case 2:
			glColor4ub(1, 160, 246, 255);
			return;
		case 3:
			glColor4ub(0, 0, 246, 255);
			return;
		case 4:
			glColor4ub(0, 255, 0, 255);
			return;
		case 5:
			glColor4ub(0, 200, 0, 255);
			return;
		case 6:
			glColor4ub(0, 144, 0, 255);
			return;
		case 7:
			glColor4ub(255, 255, 0, 255);
			return;
		case 8:
			glColor4ub(231, 192, 0, 255);
			return;
		case 9:
			glColor4ub(255, 144, 0, 255);
			return;
		case 10:
			glColor4ub(255, 0, 0, 255);
			return;
		case 11:
			glColor4ub(214, 0, 0, 255);
			return;
		case 12:
			glColor4ub(192, 0, 0, 255);
			return;
		case 13:
			glColor4ub(255, 0, 255, 255);
			return;
		case 14:
			glColor4ub(153, 85, 201, 255);
			return;
		case 15:
			glColor4ub(235, 235, 235, 255);
			return;
	}
}